package com.wjw.java.io.transformation;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

/**
 * 中文乱码问题：这时就需要用到转换流
 * InputStreamReader和OutputStreamWriter
 */
public class QuestionCode {

    public static void main(String[] args) {
        //文件路径
        //String filePath = "f:\\IO\\question_code.txt";//读取utf-8格式的文本文件,没有中文乱码
        String filePath2 = "f:\\IO\\question_code2.txt";//读取ANSI格式的文本文件,会中文乱码
        BufferedReader br = null;
        String line = "";
        try {
            //br = new BufferedReader(new FileReader(filePath));
            br = new BufferedReader(new FileReader(filePath2));
            //循环读取txt中的数据,并在控制台打印
            while ((line = br.readLine()) != null){
                System.out.println(line);
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            //这里只需关闭BufferedReader,它的底层会去关闭传入的FileReader
            if(br != null){
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
